package cn.edu.lsnu.mbti.controller;

import cn.edu.lsnu.mbti.common.R;
import cn.edu.lsnu.mbti.dto.MajorDto;
import cn.edu.lsnu.mbti.entity.Major;
import cn.edu.lsnu.mbti.entity.vo.MajorVo;
import cn.edu.lsnu.mbti.exception.CustomerException;
import cn.edu.lsnu.mbti.service.MajorService;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/major")
@Slf4j
public class MajorController {

    @Resource
    private MajorService majorService;


    /**
     * vue后台管理保存专业
     * @param major
     * @return
     */
    @PostMapping("saveMajor")
    public R<String> saveMajor(@RequestBody Major major){
        return R.success(majorService.saveMajor(major));
    }


    /**
     * vue后台管理分页查询专业集合
     * @return
     */
    @PostMapping("queryPageList")
    public R<Page<MajorDto>>  queryPageList(@RequestBody MajorVo majorVo){
        if (BeanUtil.isEmpty(majorVo)){
            throw new CustomerException("不能查询空对象");
        }
        return R.success(majorService.queryPageMajorList(majorVo));
    }


    /**
     * 根据分类id查询不同硕士下的专业接口
     * @param categoryId
     * @return
     */
    @GetMapping("queryListByCategoryId")
    public R<List<MajorDto>> queryListByCategoryId(@RequestParam String categoryId){
        return R.success(majorService.queryListByCategoryId(categoryId));
    }


    /**
     * 专业展示页（未测试mbti）
     * @param categoryId
     * @param departmentId
     * @return
     */
    @GetMapping("selectMajorWithCategoryAndDepartment")
    public R<List<Major>> selectMajorWithCategoryAndDepartment(@RequestParam String categoryId,
                                                               @RequestParam String departmentId){
        return R.success(majorService.selectMajorWithCategoryAndDepartment(categoryId,departmentId));
    }

    @GetMapping("/list")
    public R<List<Major>> list(){
        return R.success(majorService.queryList()) ;
    }
}
